//
//  CYProject_DetailHuoQuZiLiaoCollectionViewCell.m
//  cyydt
//
//  Created by chu on 2019/2/12.
//  Copyright © 2019 chu. All rights reserved.
//

#import "CYProject_DetailHuoQuZiLiaoCollectionViewCell.h"
#import "CYProjectDetail_PhonePop1View.h"
#import "CYProjectDetail_PhonePopView.h"

@implementation CYProject_DetailHuoQuZiLiaoCollectionViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.nameView.layer.cornerRadius = 3;
    self.nameView.layer.masksToBounds = YES;
    self.nameView.layer.borderWidth = 1;
    self.nameView.layer.borderColor = RGBOF(0xDAD8D8).CGColor;
    
    self.phoneView.layer.cornerRadius = 3;
    self.phoneView.layer.masksToBounds = YES;
    self.phoneView.layer.borderWidth = 1;
    self.phoneView.layer.borderColor = RGBOF(0xDAD8D8).CGColor;
    
    self.remarkView.layer.cornerRadius = 3;
    self.remarkView.layer.masksToBounds = YES;
    self.remarkView.layer.borderWidth = 1;
    self.remarkView.layer.borderColor = RGBOF(0xDAD8D8).CGColor;
    
    self.mobileView.layer.cornerRadius = 3;
    self.mobileView.layer.masksToBounds = YES;
    self.mobileView.layer.borderWidth = 1;
    self.mobileView.layer.borderColor = RGBOF(0xDAD8D8).CGColor;
    
    self.commit1Btn.layer.cornerRadius = 3;
    self.commit1Btn.layer.masksToBounds = YES;
    
    self.commit2Btn.layer.cornerRadius = 3;
    self.commit2Btn.layer.masksToBounds = YES;

}

- (IBAction)commit1Action:(UIButton *)sender {
    //获取资料
    if (self.nameTF.text.length == 0) {
        [[UIApplication sharedApplication].keyWindow makeToast:@"请填写您的姓名" duration:1.5 position:CSToastPositionCenter];
        return;
    }
    if (self.phoneTF.text.length == 0) {
        [[UIApplication sharedApplication].keyWindow makeToast:@"请填写您的手机号" duration:1.5 position:CSToastPositionCenter];
        return;
    }
    if (self.remarkTF.text.length == 0) {
        [[UIApplication sharedApplication].keyWindow makeToast:@"请填写留言信息" duration:1.5 position:CSToastPositionCenter];
        return;
    }
    [self LiuYanWithName:self.nameTF.text Phone:self.phoneTF.text Remark:self.remarkTF.text];

}

- (IBAction)commit2Action:(UIButton *)sender {
    //免费电话
    if (self.mobileTF.text.length == 0) {
        [[UIApplication sharedApplication].keyWindow makeToast:@"请填写您的手机号" duration:1.5 position:CSToastPositionCenter];
        return;
    }
    [self DianHuaWithPhone:self.mobileTF.text];

}

- (void)LiuYanWithName:(NSString *)name Phone:(NSString *)phone Remark:(NSString *)remark{
    [EasyShowLodingView showLoding];
    NSString *url = [NSString stringWithFormat:@"%@%@",HOST, @"guest-book/create"];
    NSDictionary *param = @{@"id":self.model.ID, @"type":@"3", @"truename":name, @"mobile":phone, @"content":remark, @"gfrom":@"14"};
    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param ResponseObject:^(NSDictionary *responseResult) {
        [EasyShowLodingView hidenLoding];
        NSLog(@"留言板 ---- %@",responseResult);
        if ([responseResult objectForKey:@"resError"]) {
            //            [self.view makeToast:ResErrorMessage];
        }else{
            if ([responseResult[Response_code] integerValue] == Response_value) {
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[@"message"] duration:1.5 position:CSToastPositionCenter];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[@"message"] duration:1.5 position:CSToastPositionCenter];
                
            }
        }
    }];
}


- (void)DianHuaWithPhone:(NSString *)phone{
    //    [[UIApplication sharedApplication].keyWindow endEditing:YES];
    [EasyShowLodingView showLoding];
    NSDictionary *param = @{@"itemid":self.model.ID, @"callee":phone, @"referrer":@"app", @"gform":@14};
    //将图片上传到服务器
    NSString *urlString = [Api_HOST stringByAppendingString:@"call-phone/create"];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager.requestSerializer setValue:@"multipart/form-data" forHTTPHeaderField:@"Content-Type"];

    //接收类型不一致请替换一致text/html或别的
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",
                                                         @"text/html",
                                                         @"image/jpeg",
                                                         @"image/png",
                                                         @"application/octet-stream",
                                                         @"text/json",
                                                         nil];
    [manager POST:urlString parameters:param constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        //打印下上传进度
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        [EasyShowLodingView hidenLoding];
        
        NSLog(@"responseObject--- %@",responseObject);
        if ([responseObject isKindOfClass:[NSDictionary class]]) {
            NSDictionary *responseResult = (NSDictionary *)responseObject;
            if ([responseResult[Response_code] integerValue] == Response_value) {
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[@"message"] duration:1.5 position:CSToastPositionCenter];
            }else{
                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[@"message"] duration:1.5 position:CSToastPositionCenter];
            }
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"error -- %@",error);
        [EasyShowLodingView hidenLoding];
        
    }];
    //    [[XBRequest sharedInstance] postDataWithUrl:url Parameter:param contentType:@"multipart/form-data" ResponseObject:^(NSDictionary *responseResult) {
    //        [EasyShowLodingView hidenLoding];
    //        NSLog(@"留电话 ---- %@",responseResult);
    //        if ([responseResult objectForKey:@"resError"]) {
    //            [self.view makeToast:ResErrorMessage];
    //        }else{
    //            if ([responseResult[Response_code] integerValue] == Response_value) {
    //                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
    //            }else{
    //                [[UIApplication sharedApplication].keyWindow makeToast:responseResult[Response_Message] duration:1.5 position:CSToastPositionCenter];
    //
    //            }
    //        }
    //    }];
}


@end
